import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);

const Miui = () => import(/* webpackChunkName:"login_home_welcome" */ "@/views/Miui")
const Home = () => import(/* webpackChunkName:"login_home_welcome" */ "@/components/Page/Home")
const Goods = () => import(/* webpackChunkName:"login_home_welcome" */ "@/components/Page/Goods")
const My = () => import(/* webpackChunkName:"login_home_welcome" */ "@/components/Page/My")
const Details = () => import(/* webpackChunkName:"login_home_welcome" */ "@/components/Page/Details")
const MyError = () => import(/* webpackChunkName:"login_home_welcome" */ "@/components/Page/MyError")
const Collect = () => import(/* webpackChunkName:"login_home_welcome" */ "@/components/Page/Collect")
const Shopping = () => import(/* webpackChunkName:"login_home_welcome" */ "@/components/Page/Shopping")
const confirmOrder = () => import(/* webpackChunkName:"login_home_welcome" */ "@/components/Page/ConfirmOrder")
const order = () => import(/* webpackChunkName:"login_home_welcome" */ "@/components/Page/Order")

const routes = [

    {
        path: '/',
        name: '首页',
        component: Miui,
        children: [{
            path: '',
            name: 'home',
            component: Home,

        },
        {
            path: 'goods',
            name: 'goods',
            component: Goods,
        },
        {
            path: 'my',
            name: 'my',
            component: My,
        },
        {
            path: 'details/:id',
            name: 'details',
            component: Details,
        },
        {
            path: 'collect',
            name: 'collect',
            component: Collect,
        },
        {
            path: 'shopping',
            name: 'shopping',
            component: Shopping,
        },
        {
            path: 'confirmOrder',
            name: 'confirmOrder',
            component: confirmOrder,
        },
        {
            path: 'order',
            name: 'order',
            component: order,
        },
        {
            path: 'error',
            name: 'error',
            component: MyError,
        }
        ]
    },

];

const router = new VueRouter({
    routes
});

// 全局路由导航守卫
router.beforeEach((to, from, next) => {

    if (to.path == '/Pc_good') {
        // 判断存储是否有token值 判断是否登录
        if (sessionStorage.getItem('token')) {
            // console.log(sessionStorage.getItem('04A_token'));
            next()
        } else {
            alert('请先登录')
        }
    } else if (to.path == '/Pc_collect') {
        // 判断存储是否有token值 判断是否登录
        if (sessionStorage.getItem('token')) {
            // console.log(sessionStorage.getItem('04A_token'));
            next()
        } else {
            alert('请先登录')
        }
    } else {
        next()
    }
})

export default router;